Full source code website bán hàng thương mại điện tử gần giống shopee
472.973 lượt xem;
1 /*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 * - GNU General Public License Version 2 or later (the "GPL")
11 * http://www.gnu.org/licenses/gpl.html
12 *
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 * http://www.gnu.org/licenses/lgpl.html
15 *
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
17 * http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * This is the integration file for JavaScript.
22 *
23 * It defines the FCKeditor class that can be used to create editor
24 * instances in a HTML page in the client side. For server side
25 * operations, use the specific integration system.
26 */
27
28 // FCKeditor Class
29 var FCKeditor = function( instanceName, width, height, toolbarSet, value )
30 {
31 // Properties
32 this.InstanceName = instanceName ;
33 this.Width = width || '100%' ;
34 this.Height = height || '200' ;
35 this.ToolbarSet = toolbarSet || 'Default' ;
36 this.Value = value || '' ;
37 this.BasePath = FCKeditor.BasePath ;
38 this.CheckBrowser = true ;
39 this.DisplayErrors = true ;
40
41 this.Config = new Object() ;
42
43 // Events
44 this.OnError = null ; // function( source, errorNumber, errorDescription )
45 }
46
47 /**
48 * This is the default BasePath used by all editor instances.
49 */
50 FCKeditor.BasePath = '/fckeditor/' ;
51
52 /**
53 * The minimum height used when replacing textareas.
54 */
55 FCKeditor.MinHeight = 200 ;
56
57 /**
58 * The minimum width used when replacing textareas.
59 */
60 FCKeditor.MinWidth = 750 ;
61
62 FCKeditor.prototype.Version = '2.6.3' ;
63 FCKeditor.prototype.VersionBuild = '19836' ;
64
65 FCKeditor.prototype.Create = function()
66 {
67 document.write( this.CreateHtml() ) ;
68 }
69
70 FCKeditor.prototype.CreateHtml = function()
71 {
72 // Check for errors
73 if ( !this.InstanceName || this.InstanceName.length == 0 )
74 {
75 this._ThrowError( 701, 'You must specify an instance name.' ) ;
76 return '' ;
77 }
78
79 var sHtml = '' ;
80
81 if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
82 {
83 sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ;
84 sHtml += this._GetConfigHtml() ;
85 sHtml += this._GetIFrameHtml() ;
86 }
87 else
88 {
89 var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ;
90 var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
91
92 sHtml += '<textarea name="' + this.InstanceName +
93 '" rows="4" cols="40" style="width:' + sWidth +
94 ';height:' + sHeight ;
95
96 if ( this.TabIndex )
97 sHtml += '" tabindex="' + this.TabIndex ;
98
99 sHtml += '">' +
100 this._HTMLEncode( this.Value ) +
101 '<\/textarea>' ;
102 }
103
104 return sHtml ;
105 }
106
107 FCKeditor.prototype.ReplaceTextarea = function()
108 {
109 if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
110 {
111 // We must check the elements firstly using the Id and then the name.
112 var oTextarea = document.getElementById( this.InstanceName ) ;
113 var colElementsByName = document.getElementsByName( this.InstanceName ) ;
114 var i = 0;
115 while ( oTextarea || i == 0 )
116 {
117 if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' )
118 break ;
119 oTextarea = colElementsByName[i++] ;
120 }
121
122 if ( !oTextarea )
123 {
124 alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
125 return ;
126 }
127
128 oTextarea.style.display = 'none' ;
129
130 if ( oTextarea.tabIndex )
131 this.TabIndex = oTextarea.tabIndex ;
132
133 this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
134 this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
135 }
136 }
137
138 FCKeditor.prototype._InsertHtmlBefore = function( html, element )
139 {
140 if ( element.insertAdjacentHTML ) // IE
141 element.insertAdjacentHTML( 'beforeBegin', html ) ;
142 else // Gecko
143 {
144 var oRange = document.createRange() ;
145 oRange.setStartBefore( element ) ;
146 var oFragment = oRange.createContextualFragment( html );
147 element.parentNode.insertBefore( oFragment, element ) ;
148 }
149 }
150
151 FCKeditor.prototype._GetConfigHtml = function()
152 {
153 var sConfig = '' ;
154 for ( var o in this.Config )
155 {
156 if ( sConfig.length > 0 ) sConfig += '&' ;
157 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.Config[o] ) ;
158 }
159
160 return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
161 }
162
163 FCKeditor.prototype._GetIFrameHtml = function()
164 {
165 var sFile = 'fckeditor.html' ;
166
167 try
168 {
169 if ( (/fcksource=true/i).test( window.top.location.search ) )
170 sFile = 'fckeditor.original.html' ;
171 }
172 catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
173
174 var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ;
175 if (this.ToolbarSet)
176 sLink += '&Toolbar=' + this.ToolbarSet ;
177
178 html = '<iframe id="' + this.InstanceName +
179 '___Frame" src="' + sLink +
180 '" width="' + this.Width +
181 '" height="' + this.Height ;
182
183 if ( this.TabIndex )
184 html += '" tabindex="' + this.TabIndex ;
185
186 html += '" frameborder="0" scrolling="no"></iframe>' ;
187
188 return html ;
189 }
190
191 FCKeditor.prototype._IsCompatibleBrowser = function()
192 {
193 return FCKeditor_IsCompatibleBrowser() ;
194 }
195
196 FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
197 {
198 this.ErrorNumber = errorNumber ;
199 this.ErrorDescription = errorDescription ;
200
201 if ( this.DisplayErrors )
202 {
203 document.write( '<div style="COLOR: #ff0000">' ) ;
204 document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
205 document.write( '</div>' ) ;
206 }
207
208 if ( typeof( this.OnError ) == 'function' )
209 this.OnError( this, errorNumber, errorDescription ) ;
210 }
211
212 FCKeditor.prototype._HTMLEncode = function( text )
213 {
214 if ( typeof( text ) != "string" )
215 text = text.toString() ;
216
217 text = text.replace(
218 /&/g, "&").replace(
219 /"/g, """).replace(
220 /</g, "<").replace(
221 />/g, ">") ;
222
223 return text ;
224 }
225
226 ;(function()
227 {
228 var textareaToEditor = function( textarea )
229 {
230 var editor = new FCKeditor( textarea.name ) ;
231
232 editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ;
233 editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ;
234
235 return editor ;
236 }
237
238 /**
239 * Replace all <textarea> elements available in the document with FCKeditor
240 * instances.
241 *
242 * // Replace all <textarea> elements in the page.
243 * FCKeditor.ReplaceAllTextareas() ;
244 *
245 * // Replace all <textarea class="myClassName"> elements in the page.
246 * FCKeditor.ReplaceAllTextareas( 'myClassName' ) ;
247 *
248 * // Selectively replace <textarea> elements, based on custom assertions.
249 * FCKeditor.ReplaceAllTextareas( function( textarea, editor )
250 * {
251 * // Custom code to evaluate the replace, returning false if it
252 * // must not be done.
253 * // It also passes the "editor" parameter, so the developer can
254 * // customize the instance.
255 * } ) ;
256 */
257 FCKeditor.ReplaceAllTextareas = function()
258 {
259 var textareas = document.getElementsByTagName( 'textarea' ) ;
260
261 for ( var i = 0 ; i < textareas.length ; i++ )
262 {
263 var editor = null ;
264 var textarea = textareas[i] ;
265 var name = textarea.name ;
266
267 // The "name" attribute must exist.
268 if ( !name || name.length == 0 )
269 continue ;
270
271 if ( typeof arguments[0] == 'string' )
272 {
273 // The textarea class name could be passed as the function
274 // parameter.
275
276 var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ;
277
278 if ( !classRegex.test( textarea.className ) )
279 continue ;
280 }
281 else if ( typeof arguments[0] == 'function' )
282 {
283 // An assertion function could be passed as the function parameter.
284 // It must explicitly return "false" to ignore a specific <textarea>.
285 editor = textareaToEditor( textarea ) ;
286 if ( arguments[0]( textarea, editor ) === false )
287 continue ;
288 }
289
290 if ( !editor )
291 editor = textareaToEditor( textarea ) ;
292
293 editor.ReplaceTextarea() ;
294 }
295 }
296 })() ;
297
298 function FCKeditor_IsCompatibleBrowser()
299 {
300 var sAgent = navigator.userAgent.toLowerCase() ;
301
302 // Internet Explorer 5.5+
303 if ( /*@cc_on!@*/false && sAgent.indexOf("mac") == -1 )
304 {
305 var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
306 return ( sBrowserVersion >= 5.5 ) ;
307 }
308
309 // Gecko (Opera 9 tries to behave like Gecko at this point).
310 if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
311 return true ;
312
313 // Opera 9.50+
314 if ( window.opera && window.opera.version && parseFloat( window.opera.version() ) >= 9.5 )
315 return true ;
316
317 // Adobe AIR
318 // Checked before Safari because AIR have the WebKit rich text editor
319 // features from Safari 3.0.4, but the version reported is 420.
320 if ( sAgent.indexOf( ' adobeair/' ) != -1 )
321 return ( sAgent.match( / adobeair\/(\d+)/ )[1] >= 1 ) ; // Build must be at least v1
322
323 // Safari 3+
324 if ( sAgent.indexOf( ' applewebkit/' ) != -1 )
325 return ( sAgent.match( / applewebkit\/(\d+)/ )[1] >= 522 ) ; // Build must be at least 522 (v3)
326
327 return false ;
328 }
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 * - GNU General Public License Version 2 or later (the "GPL")
11 * http://www.gnu.org/licenses/gpl.html
12 *
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 * http://www.gnu.org/licenses/lgpl.html
15 *
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
17 * http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * This is the integration file for JavaScript.
22 *
23 * It defines the FCKeditor class that can be used to create editor
24 * instances in a HTML page in the client side. For server side
25 * operations, use the specific integration system.
26 */
27
28 // FCKeditor Class
29 var FCKeditor = function( instanceName, width, height, toolbarSet, value )
30 {
31 // Properties
32 this.InstanceName = instanceName ;
33 this.Width = width || '100%' ;
34 this.Height = height || '200' ;
35 this.ToolbarSet = toolbarSet || 'Default' ;
36 this.Value = value || '' ;
37 this.BasePath = FCKeditor.BasePath ;
38 this.CheckBrowser = true ;
39 this.DisplayErrors = true ;
40
41 this.Config = new Object() ;
42
43 // Events
44 this.OnError = null ; // function( source, errorNumber, errorDescription )
45 }
46
47 /**
48 * This is the default BasePath used by all editor instances.
49 */
50 FCKeditor.BasePath = '/fckeditor/' ;
51
52 /**
53 * The minimum height used when replacing textareas.
54 */
55 FCKeditor.MinHeight = 200 ;
56
57 /**
58 * The minimum width used when replacing textareas.
59 */
60 FCKeditor.MinWidth = 750 ;
61
62 FCKeditor.prototype.Version = '2.6.3' ;
63 FCKeditor.prototype.VersionBuild = '19836' ;
64
65 FCKeditor.prototype.Create = function()
66 {
67 document.write( this.CreateHtml() ) ;
68 }
69
70 FCKeditor.prototype.CreateHtml = function()
71 {
72 // Check for errors
73 if ( !this.InstanceName || this.InstanceName.length == 0 )
74 {
75 this._ThrowError( 701, 'You must specify an instance name.' ) ;
76 return '' ;
77 }
78
79 var sHtml = '' ;
80
81 if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
82 {
83 sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ;
84 sHtml += this._GetConfigHtml() ;
85 sHtml += this._GetIFrameHtml() ;
86 }
87 else
88 {
89 var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ;
90 var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
91
92 sHtml += '<textarea name="' + this.InstanceName +
93 '" rows="4" cols="40" style="width:' + sWidth +
94 ';height:' + sHeight ;
95
96 if ( this.TabIndex )
97 sHtml += '" tabindex="' + this.TabIndex ;
98
99 sHtml += '">' +
100 this._HTMLEncode( this.Value ) +
101 '<\/textarea>' ;
102 }
103
104 return sHtml ;
105 }
106
107 FCKeditor.prototype.ReplaceTextarea = function()
108 {
109 if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
110 {
111 // We must check the elements firstly using the Id and then the name.
112 var oTextarea = document.getElementById( this.InstanceName ) ;
113 var colElementsByName = document.getElementsByName( this.InstanceName ) ;
114 var i = 0;
115 while ( oTextarea || i == 0 )
116 {
117 if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' )
118 break ;
119 oTextarea = colElementsByName[i++] ;
120 }
121
122 if ( !oTextarea )
123 {
124 alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
125 return ;
126 }
127
128 oTextarea.style.display = 'none' ;
129
130 if ( oTextarea.tabIndex )
131 this.TabIndex = oTextarea.tabIndex ;
132
133 this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
134 this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
135 }
136 }
137
138 FCKeditor.prototype._InsertHtmlBefore = function( html, element )
139 {
140 if ( element.insertAdjacentHTML ) // IE
141 element.insertAdjacentHTML( 'beforeBegin', html ) ;
142 else // Gecko
143 {
144 var oRange = document.createRange() ;
145 oRange.setStartBefore( element ) ;
146 var oFragment = oRange.createContextualFragment( html );
147 element.parentNode.insertBefore( oFragment, element ) ;
148 }
149 }
150
151 FCKeditor.prototype._GetConfigHtml = function()
152 {
153 var sConfig = '' ;
154 for ( var o in this.Config )
155 {
156 if ( sConfig.length > 0 ) sConfig += '&' ;
157 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.Config[o] ) ;
158 }
159
160 return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
161 }
162
163 FCKeditor.prototype._GetIFrameHtml = function()
164 {
165 var sFile = 'fckeditor.html' ;
166
167 try
168 {
169 if ( (/fcksource=true/i).test( window.top.location.search ) )
170 sFile = 'fckeditor.original.html' ;
171 }
172 catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
173
174 var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ;
175 if (this.ToolbarSet)
176 sLink += '&Toolbar=' + this.ToolbarSet ;
177
178 html = '<iframe id="' + this.InstanceName +
179 '___Frame" src="' + sLink +
180 '" width="' + this.Width +
181 '" height="' + this.Height ;
182
183 if ( this.TabIndex )
184 html += '" tabindex="' + this.TabIndex ;
185
186 html += '" frameborder="0" scrolling="no"></iframe>' ;
187
188 return html ;
189 }
190
191 FCKeditor.prototype._IsCompatibleBrowser = function()
192 {
193 return FCKeditor_IsCompatibleBrowser() ;
194 }
195
196 FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
197 {
198 this.ErrorNumber = errorNumber ;
199 this.ErrorDescription = errorDescription ;
200
201 if ( this.DisplayErrors )
202 {
203 document.write( '<div style="COLOR: #ff0000">' ) ;
204 document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
205 document.write( '</div>' ) ;
206 }
207
208 if ( typeof( this.OnError ) == 'function' )
209 this.OnError( this, errorNumber, errorDescription ) ;
210 }
211
212 FCKeditor.prototype._HTMLEncode = function( text )
213 {
214 if ( typeof( text ) != "string" )
215 text = text.toString() ;
216
217 text = text.replace(
218 /&/g, "&").replace(
219 /"/g, """).replace(
220 /</g, "<").replace(
221 />/g, ">") ;
222
223 return text ;
224 }
225
226 ;(function()
227 {
228 var textareaToEditor = function( textarea )
229 {
230 var editor = new FCKeditor( textarea.name ) ;
231
232 editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ;
233 editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ;
234
235 return editor ;
236 }
237
238 /**
239 * Replace all <textarea> elements available in the document with FCKeditor
240 * instances.
241 *
242 * // Replace all <textarea> elements in the page.
243 * FCKeditor.ReplaceAllTextareas() ;
244 *
245 * // Replace all <textarea class="myClassName"> elements in the page.
246 * FCKeditor.ReplaceAllTextareas( 'myClassName' ) ;
247 *
248 * // Selectively replace <textarea> elements, based on custom assertions.
249 * FCKeditor.ReplaceAllTextareas( function( textarea, editor )
250 * {
251 * // Custom code to evaluate the replace, returning false if it
252 * // must not be done.
253 * // It also passes the "editor" parameter, so the developer can
254 * // customize the instance.
255 * } ) ;
256 */
257 FCKeditor.ReplaceAllTextareas = function()
258 {
259 var textareas = document.getElementsByTagName( 'textarea' ) ;
260
261 for ( var i = 0 ; i < textareas.length ; i++ )
262 {
263 var editor = null ;
264 var textarea = textareas[i] ;
265 var name = textarea.name ;
266
267 // The "name" attribute must exist.
268 if ( !name || name.length == 0 )
269 continue ;
270
271 if ( typeof arguments[0] == 'string' )
272 {
273 // The textarea class name could be passed as the function
274 // parameter.
275
276 var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ;
277
278 if ( !classRegex.test( textarea.className ) )
279 continue ;
280 }
281 else if ( typeof arguments[0] == 'function' )
282 {
283 // An assertion function could be passed as the function parameter.
284 // It must explicitly return "false" to ignore a specific <textarea>.
285 editor = textareaToEditor( textarea ) ;
286 if ( arguments[0]( textarea, editor ) === false )
287 continue ;
288 }
289
290 if ( !editor )
291 editor = textareaToEditor( textarea ) ;
292
293 editor.ReplaceTextarea() ;
294 }
295 }
296 })() ;
297
298 function FCKeditor_IsCompatibleBrowser()
299 {
300 var sAgent = navigator.userAgent.toLowerCase() ;
301
302 // Internet Explorer 5.5+
303 if ( /*@cc_on!@*/false && sAgent.indexOf("mac") == -1 )
304 {
305 var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
306 return ( sBrowserVersion >= 5.5 ) ;
307 }
308
309 // Gecko (Opera 9 tries to behave like Gecko at this point).
310 if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
311 return true ;
312
313 // Opera 9.50+
314 if ( window.opera && window.opera.version && parseFloat( window.opera.version() ) >= 9.5 )
315 return true ;
316
317 // Adobe AIR
318 // Checked before Safari because AIR have the WebKit rich text editor
319 // features from Safari 3.0.4, but the version reported is 420.
320 if ( sAgent.indexOf( ' adobeair/' ) != -1 )
321 return ( sAgent.match( / adobeair\/(\d+)/ )[1] >= 1 ) ; // Build must be at least v1
322
323 // Safari 3+
324 if ( sAgent.indexOf( ' applewebkit/' ) != -1 )
325 return ( sAgent.match( / applewebkit\/(\d+)/ )[1] >= 522 ) ; // Build must be at least 522 (v3)
326
327 return false ;
328 }